package com.ruoyi.web.controller.stock;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.WarehouseInInfo;
import com.ruoyi.stock.service.IWarehouseInInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 入库清单Controller
 *
 * @author YwaiX
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/stock/InInfo")
public class WarehouseInInfoController extends BaseController {
    @Autowired
    private IWarehouseInInfoService warehouseInInfoService;

    /**
     * 查询入库清单列表
     */
    @PreAuthorize("@ss.hasPermi('stock:InInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(Integer warehouseInId) {
        startPage();
        List<WarehouseInInfo> list = warehouseInInfoService.selectWarehouseInInfo(warehouseInId);
        return getDataTable(list);
    }

    /**
     * 导出入库清单列表
     */
    @PreAuthorize("@ss.hasPermi('stock:InInfo:export')")
    @Log(title = "入库清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarehouseInInfo warehouseInInfo) {
        List<WarehouseInInfo> list = warehouseInInfoService.selectWarehouseInInfoList(warehouseInInfo);
        ExcelUtil<WarehouseInInfo> util = new ExcelUtil<WarehouseInInfo>(WarehouseInInfo.class);
        util.exportExcel(response, list, "入库清单数据");
    }

    /**
     * 获取入库清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('stock:InInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(warehouseInInfoService.selectWarehouseInInfoById(id));
    }

    /**
     * 新增入库清单
     */
    @PreAuthorize("@ss.hasPermi('stock:InInfo:add')")
    @Log(title = "入库清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseInInfo warehouseInInfo) {
        return toAjax(warehouseInInfoService.insertWarehouseInInfo(warehouseInInfo));
    }

    /**
     * 修改入库清单
     */
    @PreAuthorize("@ss.hasPermi('stock:InInfo:edit')")
    @Log(title = "入库清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseInInfo warehouseInInfo) {
        return toAjax(warehouseInInfoService.updateWarehouseInInfo(warehouseInInfo));
    }

    /**
     * 删除入库清单
     */
    @PreAuthorize("@ss.hasPermi('stock:InInfo:remove')")
    @Log(title = "入库清单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(warehouseInInfoService.deleteWarehouseInInfoByIds(ids));
    }
}
